package atm;

import javax.swing.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

/**
 * 菜单界面
 */
public class MenuPanel extends JPanel implements ActionListener {
    private ATMFrame atmFrame;
    private ImageIcon saveImg = new ImageIcon("images/buttonSave.jpg");
    private JButton saveBtn = new JButton(saveImg);
    private JButton searchBtn = new JButton(new ImageIcon("images/buttonFind.jpg"));
    private JButton transferBtn = new JButton("转账");
    public MenuPanel(ATMFrame atmFrame){
        this.atmFrame = atmFrame;
        this.setLayout(null);
        saveBtn.setBounds(0,150,140,50);
        saveBtn.addActionListener(this);

        searchBtn.setBounds(900,150,140,50);
        searchBtn.addActionListener(this);

        transferBtn.setBounds(0,400,140,50);
        transferBtn.addActionListener(this);
        this.add(saveBtn);
        this.add(searchBtn);
        this.add(transferBtn);
        this.setOpaque(false);
    }

    @Override
    public void actionPerformed(ActionEvent e) {
        if(saveBtn == e.getSource()){
            atmFrame.switchPanel("save");
        }else if(searchBtn == e.getSource()){
            atmFrame.getSearchPanel().showBlance();
            atmFrame.switchPanel("search");
        }else if(transferBtn == e.getSource()){
            atmFrame.switchPanel("transfer");
        }
    }
}
